/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/component/SpringIocComponentRepository.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: SpringIocComponentRepository.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.component.internal;

import org.springframework.beans.BeansException;
import org.springframework.context.support.ApplicationObjectSupport;

import com.elancom.framework.component.Component;
import com.elancom.framework.component.ComponentRepository;

/**
 * @author elancom
 * @date Apr 27, 2012
 */
public class SpringIocComponentRepository extends ApplicationObjectSupport implements ComponentRepository {

	@Override
	protected void initApplicationContext() throws BeansException {
		super.initApplicationContext();
		logger.debug("开始初始化组件模块");
		final long start = System.currentTimeMillis();
		final long end = System.currentTimeMillis();
		logger.debug("结束初始化组件模块 - 耗时" + (end - start));
	}

	@Override
	public Component getComponent(String componentName) {
		return (Component) getApplicationContext().getBean(componentName);
	}

	@Override
	public <T extends Component> T getComponent(Class<T> type, String componentName) {
		return getApplicationContext().getBean(componentName, type);
	}

	@Override
	public Component getComponentByAlias(String alias) {
		return getComponent(alias);
	}
}
